package com.kugua.zfms.shardjdbc.jdbc;

import java.sql.*;

/**
 * <p>TODO</p>
 * <p>
 * <PRE>
 * <BR>    修改记录
 * <BR>-----------------------------------------------
 * <BR>    修改日期         修改人          修改内容
 * </PRE>
 *
 * @author cuiyh9
 * @version 1.0
 * @Date Created in 2018年12月20日 21:08
 * @since 1.0
 */
public class JdbcDemo {
    static {
        System.out.println("this is static");
    }
    public JdbcDemo() {
        System.out.println("this is init");
    }

    public static void main(String[] args) {
        test();
//        testInit();
    }

    private static void testInit() {
        try {
            Class.forName("com.kugua.zfms.shardjdbc.jdbc.JdbcDemo");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static void test() {
        String driver = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/db_0?useUnicode=true&serverTimezone=UTC&characterEncoding=utf-8&autoReconnect=true&useSSL=false";
        String username = "root";
        String password = "ziroom";
        Connection conn = null;
        try {

//            System.setSecurityManager(new SecurityManager());
            String hh = System.getProperty("jdbc.drivers");
            System.out.println("hh:" + hh);
//            Class.forName(driver);
            DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
            conn = (Connection) DriverManager.getConnection(url, username, password);
            PreparedStatement ps = conn.prepareStatement("select * from test");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                Integer id = rs.getInt("id");
                System.out.println("id:" + id);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }



    }

}
